package si.cir.util;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import si.cir.entities.Novica;

public class NoviceHandler extends DefaultHandler{
	
	private List<Novica> novice = new ArrayList<Novica>();
	private Novica obvestilo;
	private String currentElement = "";
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if(qName.equals("obvestilo")){
			currentElement = qName;
			obvestilo = new Novica();
			obvestilo.setLink(attributes.getValue("povezava"));
		}
	}
	
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		if(qName.equals("obvestilo")){
			novice.add(obvestilo);
			currentElement = "";
		}
	}
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		if(currentElement.equals("obvestilo"))
			obvestilo.setNaslov(new String(ch, start, length));
	}
	
	public List<Novica> getNovice(){
		return novice;
	}
}
